package com.Brave.manager.Demo05;

public class SellTicket implements Runnable {
        private int tickets = 100;
        private Object obj = new Object();

    @Override
    public void run() {

        while (true) {
            synchronized (obj) {
                if (tickets <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + "正在卖票，还剩下" + tickets + "张票");
                }
            }
        }

    }
}
